home *** CD-ROM | disk | FTP | other *** search
- // class mag niet met kleine letters worden geschreven,
- // anders wordt deze als reserved woord behandeld.
-
-
- var htmlTagOpen = "<"; var htmlOpen = '<span cLaSs="html">' + htmlTagOpen + '</SPAN><span cLaSs="html">' ;
- var htmlTagClose = ">"; var htmlClose = '</SPAN><span cLaSs="html">' + htmlTagClose + '</SPAN>' ;
-
- // this part is language dependent. Different values needed here for PHP, ASP...
- var scriptDelimOpen = '<%';
- var scriptDelimClose = '%>'
- var scriptCommentOpen = "'";
- var scriptCommentClose = "\n";
-
- reserved = new stringArray(26)
- reserved[1] = "end";
- reserved[2] = "sub";
- reserved[3] = "set";
- reserved[4] = "do";
- reserved[5] = "loop";
- reserved[6] = "until";
- reserved[7] = "while";
- reserved[8] = "wend";
- reserved[9] = "for";
- reserved[10] = "each";
- reserved[11] = "next";
- reserved[12] = "function";
- reserved[13] = "in";
- reserved[14] = "true";
- reserved[15] = "false";
- reserved[16] = "if";
- reserved[17] = "then";
- reserved[18] = "else";
- reserved[19] = "class";
- reserved[20] = "private";
- reserved[21] = "public";
- reserved[22] = "new";
- reserved[23] = "dim";
- reserved[24] = "double";
- reserved[25] = "try";
- reserved[26] = "catch";
-
- // end language dependent part
-
- function formatScript(scr) {
- return _formatScript(scr);
- }
-
- function formatHtml(html) {
- return _formatHtml(html);
- }
-
- function formatSyntax(text) {
- return _formatSyntax(text);
- }
-
-
- function stringArray(howMany) {
- this.length = howMany;
- for (var i = 1; i <= howMany; i++) {
- this[i] = '';
- }
- }
-
- function replace(s, src, trg) {
- var sp = s.split(src);
- return sp.join(trg);
- }
- function isRegChar(ch) {
- var res = false;
- if ( (ch >= 'a') && (ch <= 'z') ) res = true;
- if ( (ch >= 'A') && (ch <= 'Z') ) res = true;
- if ( (ch >= '0') && (ch <= '9') ) res = true;
- if ( (ch == '_') ) res = true;
- return res;
- }
-
- function replaceWord(s, src, trg) {
- var sp = s.split(src);
- var res = sp[0];
- for (var q = 1; q < sp.length; q++) {
- // check if character before and character after are seperation chars, or if src is just part of another word
- if ( (!isRegChar(sp[q].charAt(0) ) ) && (!isRegChar(res.charAt(res.length - 1) ) ) ) {
- res = res + "" + trg + "" + sp[q];
- } else {
- // alert("Kan [" + src + "] niet omzetten in [" + trg + "]");
- res = res + "" + src + "" + sp[q];
- }
- }
- return res;
- }
-
- function markReservedWords(snippet) {
- for (var i = 1; i <= reserved.length; i++) {
- snippet = replaceWord(snippet, reserved[i], '<span cLaSs="res">' + reserved[i] + '</span>');
- }
- return snippet;
- }
-
- function markScriptComment(snippet) {
- comment = snippet.split(scriptCommentOpen);
- if (comment.length > 1) {
- for (var i = 1; i < comment.length; i ++) {
- commentEnd = comment[i].split(scriptCommentClose);
- comment[i] = commentEnd.join(scriptCommentClose + "</SPAN>");
- }
- snippet = comment.join('<span cLaSs="comment">' + scriptCommentOpen);
- }
- return snippet;
- }
-
- function _formatScript(scr) {
-
- scr = replace(replace(scr, '<', '<'), '>', '>');
-
- var newScr = "";
-
- var idx1, idx2;
- var preQuote;
- var quoteChar = '"';
-
- while ( (idx1 = scr.indexOf(quoteChar)) > -1) {
- preQuote = scr.substring(0, idx1);
- preQuote = markReservedWords(preQuote);
-
- preQuote = markScriptComment(preQuote);
-
- preQuote = replace(preQuote, " ", " ");
- newScr += preQuote + '<span cLaSs="string">' + quoteChar;
- scr = scr.substring(idx1 + 1, scr.length);
- idx2 = scr.indexOf(quoteChar);
- if (idx2 == -1) idx2 = scr.length;
- newScr += scr.substring(0, idx2 + 1) + "</SPAN>";
- scr = scr.substring(idx2 + 1, scr.length);
- }
- newScr += replace(markScriptComment(markReservedWords(scr)), " ", " ");
-
- scr = newScr;
- scr = replace(scr, scriptDelimOpen, '<span cLaSs="script">' + scriptDelimOpen + '</SPAN>');
- scr = replace(scr, scriptDelimClose, '<span cLaSs="script">' + scriptDelimClose + '</SPAN>');
-
- return replace(scr, "\n", "<br>\n");
- }
-
- function _formatHtml(html) {
-
- html = replace(replace(html, '<', '<'), '>', '>');
-
- var newHtml = "", nonHtml = "";
-
- var oldHtml = html;
-
- var idx1, idx2;
-
- while ( (idx1 = html.indexOf(htmlTagOpen)) > -1) {
- idx2 = html.indexOf(htmlTagClose);
-
- if (idx1 > 0) nonHtml = html.substring(0, idx1); else nonHtml = "";
-
- idxScript = html.indexOf(scriptDelimOpen);
- if (idxScript > idx1 && idxScript < idx2) {
- }
-
- if (html.substring(idx1 + htmlTagOpen.length, idx1 + 3 + htmlTagOpen.length) == "!--") {
- // we have comment!
- newHtml = newHtml + nonHtml + '<span cLaSs="comment">' + html.substring(idx1, idx2 + htmlTagClose.length) + "</SPAN>";
- } else {
- // regular html tag
- newHtml = newHtml + nonHtml + htmlOpen + html.substring(idx1 + htmlTagOpen.length, idx2) + htmlClose;
- }
- html = html.substring(idx2 + htmlTagClose.length, html.length);
- }
-
- return replace(newHtml + "" + html, "\n", "<br>\n");
-
- }
-
- function _formatSyntax(text) {
-
- text = replace(replace(text, '<', '<'), '>', '>');
-
- var newText = "";
-
- var idx1, idx2;
-
- while ( (idx1 = text.indexOf(scriptDelimOpen)) > -1) {
- idx2 =text.indexOf(scriptDelimClose);
- if (-1 == idx2) idx2 = text.length;
-
- html = formatHtml(text.substring(0, idx1));
- script = formatScript(text.substring(idx1, idx2 + scriptDelimClose.length));
-
- newText = newText + html + script;
-
- text = text.substring(idx2 + scriptDelimClose.length, text.length);
- }
- text = newText + formatHtml(text);
-
- return text;
- }
-
- function formatCSSValue(s) {
- res = "";
- for (var j = 0; j < s.length; j++) {
- c = s.charAt(j);
- if (!isNaN(c) && (c != ' ')) {
- res += '<SPAN class="CSSNumber">' + c + "</SPAN>";
- } else {
- res += c;
- }
- }
- return res;
- }
- function formatCSS(s) {
- html = "";
- while (s.indexOf("{") > -1) {
- sname = s.substring(0, s.indexOf("{"));
- html += '<SPAN class="CSSStyleName">' + sname + "</SPAN> {<BR>";
- scontent = s.substring(s.indexOf("{") + 1, s.indexOf("}"));
- selems = scontent.split(";");
- for (var i = 0; i < selems.length; i++) {
- snameval = selems[i].split(":");
- if (snameval.length >= 2) {
- html += " "
- + '<SPAN class="CSSName">' + snameval[0] + '</SPAN>'
- + ':<SPAN class="CSSValue">'
- + formatCSSValue(snameval[1])
- + '</SPAN>'
- + ";<BR>";
- }
- }
- html += "}<BR>";
- s = s.substring(s.indexOf("}") + 1, s.length);
- }
- return html;
- }
-
-
- function formatInlineCSS(s) {
- html = "";
- // while (s.indexOf('style') > -1) {
- // sname = s.substring(0, s.indexOf('style'));
- // html += '<SPAN class="CSSStyleName">' + sname + "</SPAN>";
- if (s.indexOf('style') == -1)
- scontent = s;
- else
- scontent = s.substring(s.indexOf('style') + 6, s.lastIndexOf('"'));
- selems = scontent.split(";");
- for (var i = 0; i < selems.length; i++) {
- snameval = selems[i].split(":");
- if (snameval.length >= 2) {
- html += '<SPAN class="CSSName">' + snameval[0] + '</SPAN>'
- + ':<SPAN class="CSSValue">'
- + formatCSSValue(snameval[1])
- + '</SPAN>'
- + ";";
- }
- }
- // s = s.substring(s.indexOf('"') + 1, s.length);
- // }
-
- if (s.indexOf('style') != -1)
- html += '<SPAN class="CSSName">"</SPAN>';
- return replace(html, "\n", "<br>\n");
- }
-
-